package com.baking.service.impl;

import com.baking.dao.UserMapper;
import com.baking.model.User;
import com.baking.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

/**
 * @Author:wrb
 * @Date :2020/1/8/20:09
 * @Describtion:
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userDao;

    @Override
    public List<User> getUserList(User user) {
        List<User> userList = null;
        try {
            userList = userDao.getUserList(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return userList;
    }

    @Override
    public boolean addUser(User user) {
        boolean b = false;
        try {
            b = userDao.addUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean updateUser(User user) {
        boolean b = false;
        try {
            user.setUpdateDate(new Timestamp(System.currentTimeMillis()));
            b = userDao.updateUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean deleteUser(User user) {
        boolean b = false;
        try {
            b = userDao.deleteUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }
}
